/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package IO;

import java.awt.Image;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.ImageIcon;

/**
 *
 * @author Randy
 */
public class ResourceCharacterLocation {
    String walkString = "Adelante";
    String jumpString = "Saltar";
    String standString = "Hablar";
    String atrasString = "Atras";
    
    
    public ResourceCharacterLocation() {
        ///put some stuff later
    }
    
    public ArrayList loadImgCharactersArrayList()
    {
       String charactersFolder = "/Carpeta Maestra/Personajes/";
        ArrayList<ArrayList> imgList = new ArrayList<ArrayList>();
        
        String tempPath = "";
        String basePath = new File("").getAbsolutePath();
        String searchFolder = basePath + charactersFolder;
        
        try
           {
        File folder = new File(searchFolder);
        for (File characterFolder : folder.listFiles())
        {
            if(characterFolder.isDirectory() && characterFolder.getName().startsWith("P-"))
            {
                
                File[] files = characterFolder.listFiles();
                Arrays.sort(files);
                
                for (File img : files)
                {
                    
                    if(img.getName().endsWith(".png"))  //equals("1.png"))
                    {    
                    ArrayList<Object> objectCharacterArray = new ArrayList<Object>();
                    String tmpString = img.getAbsolutePath();
                    
                    
                    objectCharacterArray.add(new ImageIcon(tmpString).getImage());
                    
                    objectCharacterArray.add(characterFolder.getName().replace("P-",""));
                    
                    objectCharacterArray.add(tmpString);                    
                 
                    imgList.add(objectCharacterArray);
                    break;
                    }
                }
                
            }         
        }              
        return imgList;        
        }catch(Exception e)
        {
            return new ArrayList();
        }
    }
    
    
    
    public ArrayList loadImgArrayList(String characterName,String actionMovement)
    {
        String prefixString;
        if(actionMovement.equals(walkString))
            prefixString = "";
        else if(actionMovement.equals(jumpString))
            prefixString = "s";
        else prefixString = "a";
                   
        ArrayList<Image> imgList = new ArrayList<Image>();
        
        String tempPath = "";
        String basePath = new File("").getAbsolutePath();
        String searchFolder = basePath + "/" + "Carpeta Maestra" + "/" +  "Personajes" + "/" + "P-" + characterName;
        System.out.println(searchFolder);
        try
           {
        File folder = new File(searchFolder);
        for (File file : folder.listFiles())
        {
            if(actionMovement.equals(jumpString) && file.getName().startsWith(prefixString)  && file.getName().endsWith(".png"))
            {
                //tempPath = //basePath + "\\" + 
                  //      "Carpeta Maestra" + "/" + characterName + "/" + file.getName(); 
               
                imgList.add(new ImageIcon(searchFolder + "/" + file.getName()).getImage());
                
            }else if
             ((actionMovement.equals("Voltear") || actionMovement.equals(walkString) || actionMovement.equals(atrasString)) && !file.getName().startsWith("s") && !file.getName().startsWith("a") && file.getName().endsWith(".png"))
            {
                //tempPath = //basePath + "\\" + 
                        //"Carpeta Maestra" + "/" + characterName + "/" + file.getName(); 
                imgList.add(new ImageIcon(searchFolder + "/" + file.getName()).getImage());                
            }else if (actionMovement.equals(standString) && file.getName().startsWith(prefixString) && file.getName().endsWith(".png"))
             {  
                //tempPath = //basePath + "\\" + 
                        //"Carpeta Maestra" + "/" + characterName + "/" + file.getName(); 
                imgList.add(new ImageIcon(searchFolder + "/" + file.getName()).getImage());                
              }
                    
        }              
        return imgList;        
        }catch(Exception e)
        {
            return new ArrayList();
        }
    }
    /*
    public ArrayList loadImgArrayList(String characterName,String actionMovement)
    {
        String prefixString;
        if(actionMovement.equals(walkString))
            prefixString = "";
        else if(actionMovement.equals(jumpString))
            prefixString = "s";
        else prefixString = "a";
                   
        ArrayList<Image> imgList = new ArrayList<Image>();
        
        String tempPath = "";
        String basePath = new File("").getAbsolutePath();
        String searchFolder = basePath + "/" + "Carpeta Maestra" + "/" + characterName;
        try
           {
        File folder = new File(searchFolder);
        for (File file : folder.listFiles())
        {
            if(!actionMovement.equals(walkString) && !actionMovement.equals("Atras") && file.getName().startsWith(prefixString)  && file.getName().endsWith(".png"))
            {
                tempPath = //basePath + "\\" + 
                        "Carpeta Maestra" + "/" + characterName + "/" + file.getName(); 
               
                imgList.add(new ImageIcon(tempPath).getImage());
                
            }else if
             ((actionMovement.equals(walkString) || actionMovement.equals("Atras")) &&  !file.getName().startsWith("s") && !file.getName().startsWith("a") && file.getName().endsWith(".png"))
            {
                tempPath = //basePath + "\\" + s
                        "Carpeta Maestra" + "/" + characterName + "/" + file.getName(); 
                imgList.add(new ImageIcon(tempPath).getImage());                
            }                
        }              
        return imgList;        
        }catch(Exception e)
        {
            return new ArrayList();
        }
    }
    */
    
    public ArrayList loadSoundArrayList()
    {
       String audioFolder = "\\Carpeta Maestra\\Audios\\";
        ArrayList<ArrayList> imgList = new ArrayList<ArrayList>();
        
        
        String basePath = new File("").getAbsolutePath();
        String searchFolder = basePath + audioFolder;
        
        try
        {
        ArrayList<String> s = new ArrayList<String>();
        File folder = new File(searchFolder);
        
        File[] files = folder.listFiles();
        Arrays.sort(files);
        
        for (File tempFile : files)     
        {
            if(tempFile.getName().endsWith(".mp3"))
            {
                s.add(tempFile.getName());
            }
        }
        return s;        
        }catch(Exception e)
        {
            return new ArrayList();
        }
    }
    
    
    
    
    
}
